package cn.edu.sdjzu.xg.eagle.controller;
import cn.edu.sdjzu.xg.eagle.entities.Announcement;
import cn.edu.sdjzu.xg.eagle.service.impl.AnnouncementImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.util.List;
@RestController
@RequestMapping("announcements")
public class AnnouncementController {

    @Autowired
    private AnnouncementImpl announcementService;

    @PostMapping
    public String addAnnouncement(@RequestBody Announcement announcement) throws SQLException {
        return announcementService.addAnnouncement(announcement);
    }

    @DeleteMapping("/{id}")
    public String deleteAnnouncement(@PathVariable int id) throws SQLException {
        return announcementService.deleteAnnouncement(id);
    }

    @PutMapping
    public String updateAnnouncement(@RequestBody Announcement announcement) throws SQLException {
        return announcementService.updateAnnouncement(announcement);
    }

    @GetMapping("/{id}")
    public Announcement getAnnouncement(@PathVariable int id) throws SQLException {
        return announcementService.findAnnouncementById(id);
    }

    @GetMapping
    public List<Announcement> getAllAnnouncements() throws SQLException {
        return announcementService.findAllAnnouncements();
    }
}